package com.xdcplus.web.controller;



import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;

import com.xdcplus.pager.vo.PageVO;
import com.xdcplus.web.common.pojo.dto.OpeJobTaskStaffingDTO;
import com.xdcplus.web.common.pojo.dto.OpeJobTaskStaffingFilterDTO;
import com.xdcplus.web.common.pojo.vo.OpeJobTaskStaffingVO;
import com.xdcplus.web.service.OpeJobTaskStaffingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Validation;
import javax.validation.constraints.NotNull;
import java.io.IOException;


/**
 * (OpeJobTaskStaffing)表服务控制层
 *
 * @author Zhecheng.Ren
 * @since 2024-10-29 14:59:20
 */
@Api(tags = "(OpeJobTaskStaffing)") 
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("opeJobTaskStaffing")
public class OpeJobTaskStaffingController extends AbstractController {

    @Autowired
    private OpeJobTaskStaffingService opeJobTaskStaffingService;

    @ApiOperation("新增")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveOpeJobTaskStaffing(@RequestBody OpeJobTaskStaffingDTO opeJobTaskStaffingDTO) {

        log.info("saveOpeJobTaskStaffing {}", opeJobTaskStaffingDTO.toString());

        opeJobTaskStaffingDTO.setCreatedUser(getAccount());
        opeJobTaskStaffingService.saveOpeJobTaskStaffing(opeJobTaskStaffingDTO);

        return ResponseVO.success();
    }

    @ApiOperation("修改")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateOpeJobTaskStaffing(@RequestBody OpeJobTaskStaffingDTO opeJobTaskStaffingDTO) {

        log.info("updateOpeJobTaskStaffing {}", opeJobTaskStaffingDTO.toString());

        opeJobTaskStaffingDTO.setUpdatedUser(getAccount());
        opeJobTaskStaffingService.updateOpeJobTaskStaffing(opeJobTaskStaffingDTO);

        return ResponseVO.success();
    }

    @ApiOperation("删除")
    @DeleteMapping(value = "/{opeJobTaskStaffingId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "opeJobTaskStaffingId", dataTypeClass = Long.class, value = "ID", required = true),
    })
    public ResponseVO deleteOpeJobTaskStaffingLogical(@PathVariable("opeJobTaskStaffingId")
                                         @NotNull(message = "ID不能为空") Long opeJobTaskStaffingId) {

        log.info("deleteOpeJobTaskStaffingLogical {}", opeJobTaskStaffingId);

        opeJobTaskStaffingService.deleteOpeJobTaskStaffingLogical(opeJobTaskStaffingId);

        return ResponseVO.success();
    }
    
    @ApiOperation("批量删除")
    @DeleteMapping(value = "/deleteByIds/{opeJobTaskStaffingIds}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "opeJobTaskStaffingId", dataTypeClass = Long.class, value = "ID", required = true),
    })
    public ResponseVO deleteOpeJobTaskStaffingLogical(@PathVariable("opeJobTaskStaffingIds")
                                         @NotNull(message = "ID不能为空") String opeJobTaskStaffingIds) {

        log.info("deleteOpeJobTaskStaffingByIds {}", opeJobTaskStaffingIds);

        opeJobTaskStaffingService.deleteOpeJobTaskStaffingByIds(opeJobTaskStaffingIds);

        return ResponseVO.success();
    }

    @ApiOperation("查询")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<PageVO<OpeJobTaskStaffingVO>> findOpeJobTaskStaffing(OpeJobTaskStaffingFilterDTO opeJobTaskStaffingFilterDTO) {

        log.info("findOpeJobTaskStaffing {}", opeJobTaskStaffingFilterDTO);

        Validation.buildDefaultValidatorFactory().getValidator().validate(opeJobTaskStaffingFilterDTO);

        return ResponseVO.success(opeJobTaskStaffingService.queryOpeJobTaskStaffing(opeJobTaskStaffingFilterDTO));
    }

    @ApiOperation("根据设备号及当前时间查询人员配置")
    @GetMapping(value = "/single/{toolCode}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "toolCode", dataTypeClass = String.class, value = "toolCode", required = true),
    })
    public ResponseVO queryOpeJobTaskStaffingByToolCode(@PathVariable("toolCode")
                                                      @NotNull(message = "设备号不能为空") String toolCode) {

        log.info("queryOpeJobTaskStaffingByToolCode {}", toolCode);

        return ResponseVO.success(opeJobTaskStaffingService.queryOpeJobTaskStaffingByToolCode(toolCode));
    }

    @ApiOperation("导入")
    @PostMapping("/import")
    public ResponseVO<Void> importExcelFile(@RequestParam("file") MultipartFile file) throws IOException {
        opeJobTaskStaffingService.importData(file, getAccount());
        return ResponseVO.success();
    }

    @ApiOperation("预警信息导出")
    @PostMapping(value = "/export", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<Void> exportExcel(@RequestBody OpeJobTaskStaffingFilterDTO opeJobTaskStaffingFilterDTO, HttpServletResponse response) throws IOException {
        opeJobTaskStaffingService.exportData(opeJobTaskStaffingFilterDTO, response);
        return ResponseVO.success();
    }


    @ApiOperation("模板下载")
    @PostMapping(value = "/templateDownload", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<Void> templateDownload(HttpServletResponse response) throws IOException {
        opeJobTaskStaffingService.templateDownload(response);
        return ResponseVO.success();
    }


}
